package org.i1510.common.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.i1510.common.bean.PageBean;
import org.i1510.common.dao.ISysRoleDao;
import org.i1510.common.po.SysRole;
import org.i1510.common.service.ISysRoleService;
import org.i1510.common.utils.BeanUtils;
import org.i1510.common.utils.web.ResultMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("iSysRoleService")
public class SysRoleServiceImpl extends BaseServiceImpl implements
		ISysRoleService {
	@Autowired
	private ISysRoleDao iSysRoleDao;

	@Transactional
	public ResultMapper saveAll(List<SysRole> list) {

		ResultMapper mapper = ResultMapper.generateFailure();

		List<SysRole> listSaved = iSysRoleDao.save(list);
		
		if (listSaved == null) {
			return null;
		}
		mapper = ResultMapper.generateSuccess();
		mapper.appendResult("baseRtn", listSaved);
		return mapper;
	}

	public ResultMapper save(SysRole basePo) {

		ResultMapper mapper = ResultMapper.generateFailure();
		SysRole saved = iSysRoleDao.save(basePo);
		if (saved == null) {
			return null;
		}	
		mapper = ResultMapper.generateSuccess();
		mapper.appendResult("baseRtn", saved);
		return mapper;
	}
	public ResultMapper delete(String fdId) {

		ResultMapper mapper = ResultMapper.generateFailure();
		iSysRoleDao.delete(fdId);
		mapper = ResultMapper.generateSuccess();
		return mapper;
	}
	
	public SysRole findById(String fdId){
		SysRole  SysRole = iSysRoleDao.findById(fdId);
		return SysRole;
	}
	public List<SysRole> findByIds(List<String> fdIds){
		return (List<SysRole>) iSysRoleDao.findAll(fdIds);
	}
	public List getPage(SysRole sysRole, PageBean pageBean,Map conditions) {
		Map map = new HashMap();
		// Bean转成Map
		BeanUtils.ObjectCopyMap(sysRole, map);
		map.put("intPageIndex", pageBean.getIntPageIndex());
		map.put("intPageSize", pageBean.getIntPageSize());
		map.putAll(conditions);
		List list = this.queryForListBySql("sysRoleSql.getPage", map);
		return list;
	}

	public int getPageCount(SysRole sysRole,Map conditions) {
		Map map = new HashMap();
		// Bean转成Map
		BeanUtils.ObjectCopyMap(sysRole, map);
		map.putAll(conditions);
		List list = this.queryForListBySql("sysRoleSql.getPageCount", map);
		return list.size();
	}

}